package b2c

import (
	"jlpay-sdk-go/pkg/jlpay/core"
	"jlpay-sdk-go/pkg/jlpay/models/trans/b2c"
	"jlpay-sdk-go/pkg/jlpay/services"
)

// MicroPayService 微支付服务
type MicroPayService struct {
	*services.BaseService
}

// NewMicroPayService 创建微支付服务
func NewMicroPayService(config *core.Config) *MicroPayService {
	return &MicroPayService{
		BaseService: services.NewBaseService(config),
	}
}

// MicroPay 微支付
func (s *MicroPayService) MicroPay(request *b2c.MicroPayRequest) (*b2c.MicroPayResponse, error) {
	response := b2c.NewMicroPayResponse()
	err := s.Post(request, response, "/open/trans/micropay")
	if err != nil {
		return nil, err
	}
	return response, nil
}

// MicroPayPreAuth 微支付预授权
func (s *MicroPayService) MicroPayPreAuth(request *b2c.MicroPayPreAuthRequest) (*b2c.MicroPayPreAuthResponse, error) {
	response := b2c.NewMicroPayPreAuthResponse()
	err := s.Post(request, response, "/open/trans/micropaypreauth")
	if err != nil {
		return nil, err
	}
	return response, nil
}
